﻿@addTagHelper *, WebVella.Erp.Plugins.Core
@addTagHelper *, WebVella.Erp.Web
@addTagHelper *, WebVella.TagHelpers
@using WebVella.Erp.Web.Utils;
@using WebVella.Erp.Api.Models;
@using WebVella.Erp.Web.Models;
@using WebVella.Erp.Plugins.Project.Components;
@using WebVella.Erp.Plugins.Project.Model;
@using WebVella.TagHelpers.Models;
@{
	var options = (PcProjectWidgetTasksQueue.PcProjectWidgetTasksQueueOptions)ViewBag.Options;
	var records = (List<EntityRecord>)ViewBag.Records;
	var gridColumn = new List<WvGridColumnMeta>() {
		new WvGridColumnMeta(){
			Name = "name",
			Width = "",
			Label = "name"
		},
		new WvGridColumnMeta(){
			Name = "user",
			Width = "200px",
			Label = "user"
		},
		new WvGridColumnMeta(){
			Name = "date",
			Width = "120px",
			Label = "date"
		}
	};
}
@if(records.Count > 0){
<wv-grid small="true" columns="@gridColumn"  has-tfoot="false" has-thead="false">
	@foreach (var record in records)
	{
		var dateString = "no target date";
		var dateClass = "go-gray";
		if (record["date"] != null) {
			dateClass = "";
			dateString = ((DateTime)record["date"]).ToString("dd MMM yyyy");
		}

		@switch (options.Type)
		{
			case TasksDueType.EndTimeDueToday:
				dateClass = "go-orange";
				break;
			case TasksDueType.EndTimeOverdue:
				dateClass = "go-red";
				break;
			default:
				break;
		}
		<wv-grid-row>
			<wv-grid-column>@Html.Raw((string)record["task"])</wv-grid-column>
			<wv-grid-column width="200px">@Html.Raw((string)record["user"])</wv-grid-column>
			<wv-grid-column width="120px" class="@dateClass">@dateString</wv-grid-column>
		</wv-grid-row>
	}
</wv-grid>
}
else { 
	@switch (options.Type)
	{
		case TasksDueType.EndTimeDueToday:
			<div class="alert alert-info p-2 m-0">No tasks due today</div>
			break;
		case TasksDueType.EndTimeOverdue:
			<div class="alert alert-info p-2 m-0">No overdue tasks</div>
			break;
		case TasksDueType.EndTimeNotDue:
			<div class="alert alert-info p-2 m-0">No upcoming tasks</div>
			break;
		default:
			<div class="alert alert-info p-2 m-0">No overdue tasks</div>
			break;
	}
}